import UIKit

// 枚举: 有限状态集合
// 星期 性别 月份 季节
enum WeekDay {
  case Mon, Tue, Wed, Thu, Fri, Sat, Sun
}

// case可以写一行,可以多行
enum Season {
  case Spring, Summer, Autumn, Winter
}

enum Direction {
  case South
  case North
  case East
  case West
}

// 类型推断
var a = WeekDay.Fri
print(type(of: a))
a = .Sun // 可以省略类型
print(a)

// 枚举匹配
var d = Direction.East

switch d {
  case .South:
    print("南方")
  case .North:
    print("北方")
  case .East:
    print("东方")
  case .West:
    print("西方")
}

// 关联值: 携带数据的枚举状态,该数据叫关联值
enum PlayerState {
  case walk
  case run(speed: Int)
  case fly(speed: Int, height: Int)
}

var a1 = PlayerState.walk
var a2 = PlayerState.run(speed: 6)
var a3 = PlayerState.fly(speed: 1000, height: 2000)
switch a3 {
  case .walk:
    print("我在散步")
  case let .run(speed):
    print("我在跑步,速度:\(speed)")
  case let .fly(speed, height):
    print("我坐飞机,速度:\(speed), 高度: \(height)")
}

// 原始值: 可以自己指定类型
enum Gender: String {
  case man
  case woman
  case unknow
}

print(Gender.woman.rawValue) // rawValue在指定原始值之后才可以使用此属性
